package com.atguigu07.encapsulation;

/**
 * ClassName: AnimalTest
 * Package: com.atguigu07.encapsulation
 * Description:
 *
 * @Author 姜
 * @Create 2023/11/20 16:20
 * @Version 1.0
 */
public class AnimalTest {
    public static void main(String[] args) {
        Animal animal1 = new Animal();
        animal1.name = "兔子";
//        animal1.legs = 4;
        animal1.setLegs(4);
        System.out.println("name = " + animal1.name + ", legs = " + animal1.getLegs());
        animal1.eat();
    }
}

class Animal {
    // 属性
    String name;
    private int legs;

    public void setLegs(int l) {
        if (l >= 0 && l % 2 == 0) {
            legs = l;
        } else {
            System.out.println("你输入的参数有误");
        }
    }

    public int getLegs(){
        return legs;
    }

    public void eat() {
        System.out.println("动物觅食");
    }
}